i2c: bcm2835: Fix hang for writing messages larger than 16 bytes
authorNoralf Trønnes <noralf@tronnes.org>
Sat, 17 Sep 2016 13:07:10 +0000 (15:07 +0200)
committerpopcornmix <popcornmix@gmail.com>
Mon, 20 Feb 2017 20:28:38 +0000 (20:28 +0000)
commit054e94ea43b23059bcee2378db39b440bb11283f
tree8c189c0ad30c73a4f7f1ec38af9ed3fdb56ba5d5
parentb05b2efb4823cfc35dc8b4f71637658682539fe8
i2c: bcm2835: Fix hang for writing messages larger than 16 bytes

Writing messages larger than the FIFO size results in a hang, rendering
the machine unusable. This is because the RXD status flag is set on the
first interrupt which results in bcm2835_drain_rxfifo() stealing bytes
from the buffer. The controller continues to trigger interrupts waiting
for the missing bytes, but bcm2835_fill_txfifo() has none to give.
In this situation wait_for_completion_timeout() apparently is unable to
stop the madness.

The BCM2835 ARM Peripherals datasheet has this to say about the flags:
  TXD: is set when the FIFO has space for at least one byte of data.
  RXD: is set when the FIFO contains at least one byte of data.
  TXW: is set during a write transfer and the FIFO is less than full.
  RXR: is set during a read transfer and the FIFO is or more full.

Implementing the logic from the downstream i2c-bcm2708 driver solved
the hang problem.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Martin Sperl <kernel@martin.sperl.org>
drivers/i2c/busses/i2c-bcm2835.c